const http = require("http");
const url = require("url");
http.createServer(app).listen(8002);

const G = {};
const app = function (req, res) {
    res.writeHead(200, {"Context-Type": "text/html;charset=utf-8"});
    let pathName = url.parse(req.url).pathname;
    if (!pathName.endsWith("/")) {
        pathName += "/"
    }
    console.log(pathName);
    if (G[pathName]) {
        G[pathName](req, res);
    } else {
        res.end("路由不存在")
    }
};


app.get = function (string, callback) {
    if (!string.endsWith('/')) {
        string += "/"
    }
    if (!string.startsWith('/')) {
        string = "/" + string
    }
    console.log(string);
    G[string] = callback;
};

app.get("login", function (req, res) {
    res.end("ssssssssssssssss")
});

app.get("requer", function (req, res) {
    res.end("requer")
});
